#!/bin/bash

domain=$1
problem=`basename $2`
file=$3

# create directory for datafiles
mkdir -p data

# extract data
grep -h "decisions)" $file |
  awk 'BEGIN { FS="[=,() ]"; } \
             { if( $1 == "optimal" || $1 == "greedy" || $1 == "random" ) {
                   printf "%s,%s,%s,NA,NA,NA,NA,NA,%s,%s,%s,%s\n",domain,problem,$1,$3,$4,$7,$9;
               } else if( $1 == "ao3" || $1 == "ao4" || $1 == "aot" || $1 == "aot*" || $1 == "aot-random" || $1 == "aot-value" || $1 == "aot2" || $1 == "aot-value2" ) {
                   printf "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n",domain,problem,$1,$2,$4,$6,$8,$10,$13,$14,$17,$19;
               } else {
                   printf "%s,%s,%s,%s,%s,%s,%s,NA,%s,%s,%s,%s\n",domain,problem,$1,$2,$4,$6,$8,$11,$12,$15,$17;
               }
             }' domain=$domain problem=$problem >> data/$problem.csv

